package gamecode;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class SpaceBackground {

	private List<EntityStar> stars;
	
	public SpaceBackground(int numStars, Rectangle bounds, EntityPlayerShip player) {
		stars = new ArrayList<EntityStar>();
		populateStars(numStars, bounds, player);
	}
	
	private void populateStars(int numStars, Rectangle bounds, EntityPlayerShip player) {
		Random rnd = new Random();
		rnd.setSeed(49737753);
		for(int i = 0; i < numStars; i++) {
			int maxColor = 100; // maximum random color int
			stars.add(new EntityStar(Color.getHSBColor(rnd.nextInt(maxColor), rnd.nextInt(maxColor), rnd.nextInt(maxColor)), new DPoint((rnd.nextDouble()*bounds.width)+(player.getPosition().getX()-bounds.width/2), (rnd.nextDouble()*bounds.height)+(player.getPosition().getY()-bounds.height/2))));
		}
	}
	
	public void drawStars(Graphics2D g2d, Rectangle bounds, EntityPlayerShip player) {
		for(EntityStar star : stars) {
			star.update(bounds, player);
			star.drawEntity(g2d, bounds, player);
		}
	}
}
